#include <bits/stdc++.h>
#include <climits>
using namespace std;

//积分图

int m,n;

int main(){
    cin>>m>>n;
    vector<vector<int>> arr(m+1, vector<int>(n+1, 0));
    for(int i=1; i<=m; ++i){
        for(int j=1; j<=n; ++j){
            cin>>arr[i][j];
            arr[i][j]+=(arr[i-1][j]+arr[i][j-1]-arr[i-1][j-1]);
        }
    }

    int ans = INT_MAX;
    for(int i=1; i<m; ++i){
        ans = min(ans, abs(arr[m][n]-(arr[i][n]<<1)));
    }
    for(int j=1; j<n; ++j){
        ans = min(ans, abs(arr[m][n]-(arr[m][j]<<1)));
    }
    cout<<ans;
}